
package Communications;

import java.io.*;
import java.net.*;
import java.util.*;

public class MultiUnicastServerThread extends Thread {

    private Queue<String> inputStream = null;
    private PrintWriter out;
    private BufferedReader in;
    private Socket socket;

    public MultiUnicastServerThread(MultiUnicastServer _server, Socket _socket) {
        this.inputStream = _server.getInputStream();
        this.socket = _socket;
        try {
            out = new PrintWriter(socket.getOutputStream(), true);
            in = new BufferedReader(
                    new InputStreamReader(
                    socket.getInputStream()));
        } catch (Exception e) {
        }
    }

    @Override
    public void run() {
        try {

            String inputLine;
            while (true) {
                inputLine = in.readLine();
                if (inputLine != null) {
                    inputStream.add(inputLine);
                }
            }
        } catch (Exception ex) {
        }
    }

    public void close() {
        try {
            out.close();
            in.close();
            socket.close();
        } catch (Exception e) {
        }
    }

    public void sendMessage(String s) {
        out.println(s);
    }
}
